-
How to get all the positions of multiple matches
import re p = re.compile("ab", re.IGNORECASE) for m in p.finditer("abcdefgAbdc"): print m.start(), m.group()
0 ab 7 ab
-
Substitution
import re test = "<h1>title</h1>" test re.sub("\<.*?\>","",test)
>>> test = "<h1>title</h1>" >>> test '<h1>title</h1>' >>> re.sub("\<.*?\>","",test) 'title'
-
Minimal matching
import re test = "<h1>title</h1>" test re.sub("\<.*\>","",test) re.sub("\<.*?\>","",test)
>>> test = "<h1>title</h1>" >>> test '<h1>title</h1>' >>> re.sub("\<.*\>","",test) '' >>> re.sub("\<.*?\>","",test) 'title'
Hide Comments